from fastapi import Body
from server.redis.conversations import backup_and_clear_key
from startup import REDIS
from server.utils import BaseResponse


def clear_histories(uid: str = Body(..., description="用户ID", examples=["1234567890"]),
                    knowledge_base_name: str = Body(..., description="知识库名称",
                                                    examples=["samples"])) -> BaseResponse:
    # 需要异常处理
    try:
        return backup_and_clear_key(uid, REDIS["host"], REDIS["port"], REDIS["db"][knowledge_base_name])
    except Exception as e:
        return BaseResponse(code=500, msg=str(e))
